<template>
  <!--出库列表  唐美莉 -->
  <section>
    <table
      border="0"
      width="100%"
      style="border-spacing: 0;border-collapse: collapse;"
    >
      <tr>
        <td>
          <el-form :inline="true">
            <el-form-item>
              <el-select
                v-model="form.outWay"
                clearable
                filterable
                placeholder="请选择出库方式"
              >
                <el-option label="全部" :key="-1" value></el-option>
                <el-option
                  v-for="(item, index) in typeList"
                  :key="index"
                  :value="item.id"
                  :label="item.desc"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="form.startTime"
                type="date"
                :editable="true"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptions"
                placeholder="出库开始时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-date-picker
                v-model="form.endTime"
                type="date"
                :editable="true"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptions"
                placeholder="出库结束时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                circle
                icon="el-icon-search"
                @click="getData(-1)"
              ></el-button>
            </el-form-item>
            <el-form-item>
              <el-button
                type="primary"
                :disabled="!qxBtns.add"
                plain
                @click="addDurg(null)"
                >+添加</el-button
              >
            </el-form-item>
          </el-form>
        </td>
        <td style="text-align:right;vertical-align: top;">
          <el-button @click="exportExcel()" plain>导出</el-button>
        </td>
      </tr>
    </table>

    <el-table :data="tableList" style="width: 100%">
      <el-table-column prop="stockCode" label="出库单号"> </el-table-column>
      <el-table-column prop="applyDate" label="申领日期"> </el-table-column>
      <el-table-column prop="outWay" label="出库方式">
        <template slot-scope="scope">
          {{scope.row.outWay | changeAssist(typeList)}}
        </template>
      </el-table-column>
      <el-table-column prop="receiveDeptName" label="领用科室">
      </el-table-column>
      <el-table-column prop="operatorName" label="经手人"> </el-table-column>
      <el-table-column prop="receiveUserName" label="领用人员">
      </el-table-column>
      <el-table-column prop="createUserName" label="出库人"> </el-table-column>
      <el-table-column prop="outDate" label="出库日期"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <label v-if=" scope.row.outWay==14"> {{ scope.row.status == 1 ? "审核通过" : (scope.row.status==0?"待审核":'审核未通过') }}</label> 
          <label v-else>{{scope.row.status == 1 ?"审核通过":"待审核"}}</label>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-link
            v-if="qxBtns.update && scope.row.status == 0 && scope.row.outWay!=14"
            :underline="false"
            @click="addDurg(scope.row)"
            type="primary"
            >修改</el-link
          >&nbsp;
          <el-link
            v-if="qxBtns.audit && scope.row.status == 0"
            :underline="false"
            type="primary"
            @click="getDetail(scope.row)"
            >审核</el-link
          >&nbsp;
          <el-link
            v-if="qxBtns.audit && scope.row.status != 0"
            :underline="false"
            type="primary"
            @click="getDetail(scope.row)"
            >查看详情</el-link
          >&nbsp;
        </template>
      </el-table-column>
    </el-table>
    <div
      v-if="tableList.length == 0"
      style="color:#999;padding:10px 0;text-align:center;"
    >
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <!-- <set v-model="dialogEdit" :curItem="curItem" @success="getData"></set> -->
  </section>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  name: "storageList",
  data() {
    return {
      dialogJoin: false,
      dialogEdit: false,
      curItem: null,
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tableList: [],
      form: {
        hpId: "",
        startTime: "", //入库时间
        endTime: "", //出库时间
        type: 2,
        source: 1,
        outWay: "",
        status: "",
      },
      rules: {
        type: [{ required: true, message: "此项必选", trigger: "change" }],
      },
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() > Date.now();
        },
      },
      typeList: [],
      qxBtns: {},
      dataList: [],
      distype: "2",
      setType: "1",
    };
  },
  created() {
    let th = this;
    th.form.hpId = th.adminUser.hpId;
    th.getQX();
    th.getData();
    th.getBasicData();
    // th.form.putInStorageStartTime = th.getDate(0);
    // th.form.putInStorageEndTime = th.getDate(1);
  },
  methods: {
    onJoin(obj) {
      this.dialogJoin = true;
      this.curItem = obj;
    },
    getData(type, id) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      if (id != undefined) {
        if (id == -1) {
          th.form.drugTypeId = "";
        } else {
          th.form.drugTypeId = id;
        }
      }
      let j = { timeRangeInfo: {} };
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      j.timeRangeInfo.startTime = th.form.startTime;
      j.timeRangeInfo.endTime = th.form.endTime;
      th.showLoading();
      th.$api.getPutStorge(j).then((res) => {
        if (res.executed) {
          if (res.dataBody != undefined) {
            th.tableList = res.dataBody.list;
            th.pager.total = res.dataBody.total;
          } else {
            th.tableList = [];
            th.pager.total = 0;
          }
        }
        th.showLoading(false);
      });
    },
    addDurg(obj) {
      let th = this;
      let j = {};
      if (obj != null) {
        j = {
          id: th.jiaMi(obj.id),
        };
      } else {
        j = {
          id: th.jiaMi(0),
        };
      }
      th.$router.push({
        path: "/page/editstock",
        query: th.getUrlToken(j),
      });
    },
    getDetail(obj) {
      let j = {};
      if (obj != null) {
        j = {
          id: this.jiaMi(obj.id),
          type: 1,
        };
      } else {
        j = {
          id: this.jiaMi(0),
          type: 1,
        };
      }
      let js = this.$utils.JsonToUrl(this.getUrlToken(j));
      obj.outWay == 14
        ? this.addNavMenu("出库详情", "/page/receiveDetail?" + js, "")
        : this.addNavMenu("出库详情", "/page/drugDetail?" + js, "");
      obj.outWay == 14
        ? this.$router.push({
            path: "/page/receiveDetail",
            query: this.getUrlToken(j),
          })
        : this.$router.push({
            path: "/page/drugDetail",
            query: this.getUrlToken(j),
          });
    },
    getBasicData() {
      let th = this;
      th.getCommonConfigByKey("出库方式").then((res) => {
        th.typeList = res;
      });
    },
    exportExcel() {
      let th = this;
      let j = {};
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      j.pageSize = "1000";
      let out = [];
      th.typeList.map((item, index) => {
        out[item.id] = item.desc;
      });
      th.$api.getPutStorge(j).then((res) => {
        if (res.executed) {
          if (res.dataBody != undefined) {
            let data = res.dataBody.list;
            Excel(
              data,
              [
                { key: "stockCode", name: "出库单号" },
                { key: "outDate", name: "出库日期" },
                { key: "outWay", name: "出库方式", enum: out, type: "enum" },
                { key: "receiveDeptName", name: "领用科室" },
                { key: "receiveUserName", name: "领用人员" },
                { key: "createUserName", name: "出库人" },
                {
                  key: "status",
                  name: "状态",
                  enum: { 1: "正常", 2: "待审核", 0: "待审核" },
                  type: "enum",
                },
              ],
              "药品出库列表"
            );
          }
        }
        th.showLoading(false);
      });
    },
  },
  components: {
    // set: () => import("./_com/setVip.vue")
  },
};
</script>
